<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{$Think.config.title}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">
                    <div class="box box-warning">
                        <div class="box-header">
                            <h3 class="box-title">{$action}</h3>
                        </div>
                        <!-- /.box-header -->
                        <div class="box-body">



                            <form method="POST" action="{:addons_url('Guestbook://Guestbook/delAll')}" id="messageForm">
                                <div class="portlet-body">
                                    <div class="clearfix">
                                        <div class="btn-group">
                                            <button type="submit" class="btn red delAll" name="delAll" value='1'><i
                                                    class="icon-remove icon-white">
                                            </i> 批量删除
                                            </button>
                                        </div>
                                    </div>
                                    <table class="table table-striped table-bordered table-hover"
                                           id="post_table">
                                        <thead>
                                        <tr>
                                            <th style="width: 8px;">
                                                <input type="checkbox" class="group-checkable"
                                                       data-set="#post_table .checkboxes"/>
                                            </th>
                                            <th style="width:100px;">姓名</th>
                                            <th style="width:200px;">标题</th>
                                            <th>内容</th>
                                            <th style="width:130px;">留言日期</th>
                                            <th style="width:200px;">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <foreach name="message" item="v">
                                            <tr class="odd gradeX">
                                                <td><input type="checkbox" class="checkboxes" value="{$v['id']}"
                                                           name="message[]"/>
                                                </td>
                                                <td><a href="#">{$v.name}</a></td>
                                                <td>{$v.title}</td>
                                                <td>
                                                    {$v.content}
                                                </td>
                                                <td>{:getTimestamp($v['date'],'Y-m-d H:i') }</td>
                                                <td>
                                                    <notpresent name="v.reply">
                                                        <a class="btn mini green" href="javascript:;"
                                                           onclick="ajax_reply({$v.id})">回复</a>
                                                        &nbsp;&nbsp;&nbsp;
                                                    </notpresent>
                                                    <a class="btn mini red del_btn_{$v.id}" href="javascript:;"
                                                       onclick="ajax_del({$v.id})">删除</a>
                                                    &nbsp;&nbsp;&nbsp;
                                                    <eq name="v.status" value="0">
                                                        <a href="javascript:;" onclick="ajax_approve({$v.id})"><span
                                                                class="label label-inverse approve_{$v.id}">待审核</span></a>
                                                    </eq>
                                                </td>
                                            </tr>
                                            <tr class="reply reply_{$v.id}" style="display:none;">
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td>
                                                    <div class="control-group">
                                                        <label class="control-label"></label>

                                                        <div class="controls">
                                                            <textarea name="reply"
                                                                      class="large m-wrap reply_content_{$v.id}"
                                                                      rows="3"></textarea>
                                                        </div>
                                                    </div>
                                                    <div class="form-actions">
                                                        <button type="button" class="btn blue reply_btn"><i
                                                                class="icon-ok"></i> 回复
                                                        </button>
                                                        <button type="reset" class="btn">重置</button>
                                                    </div>
                                                </td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                        </foreach>
                                        </tbody>
                                    </table>

                                </div>
                            </form>
                            <div class="pagination">
                                <ul>{$pager}</ul>
                            </div>


                        </div>
                    </div>
                </div>
            </div>


        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>


<script type="text/javascript">
    function ajax_reply(id) {
        $(".reply").fadeOut();
        $(".reply_" + id).fadeIn();

        $(".reply_btn").click(function () {
            var url = "{:addons_url('Guestbook://Guestbook/reply')}";
            $(".reply_btn").text("正在回复...");

            var reply = $(".reply_content_" + id).val();
            // alert(reply);
            $.post(url, {id: id, reply: reply},
                    function (data) {
                        if (data.status == 1) {
                            window.location.reload(true);
                        }
                        else {
                            // alert(data);
                        }
                        window.location.reload(true);
                    });
        });
    }

    function ajax_del(id) {
        var url = "{:addons_url('Guestbook://Guestbook/del')}";
        $(".del_btn_" + id).text("正在删除...");

        $.post(url, {id: id},
                function (data) {
                    if (data.status == 1) {
                        window.location.reload(true);
                    }
                    else {
                        // alert(data);
                    }
                    window.location.reload(true);
                });
    }

    function ajax_approve(id) {
        var url = "{:addons_url('Guestbook://Guestbook/approve')}";
        $(".approve_" + id).text("正在审核...");
        $.post(url, {id: id},
                function (data) {
                    if (data.status == 1) {
                        window.location.reload(true);
                    }
                    else {
                        // alert(data);
                    }
                    window.location.reload(true);
                });
    }

    $(".delAll").click(function () {
        $("#messageForm").submit();
    });
</script>

</body>
</html>


